<template>
  <div class="tpl16-swiper"
      :style="tplItemData.modulePadding || tplItemData.modulePadding ==0?'padding-top:'+tplItemData.modulePadding+'px;padding-bottom:'+tplItemData.modulePadding+'px;':'padding-top:5px;padding-bottom:5px;'">
    <!-- 折叠轮播 -->
    <div ref="getHeight"  class="imgAdv-box" v-if="tplItemData.showType == 1">
      <!-- TODO 小程序端用swiper -->
      <wx-swiper class="my-swipe" :circular="true" :style="`height: ${imgadvWxH}`" indicator-color="#ebedf0" indicator-active-color="#FE5000" :autoplay="autoplay" :indicator-dots="showIndicators">
        <wx-swiper-item v-for="(item,index) in tplItemData.dataset" :key="index">
          <a @click="openLink(item.link)">
            <img :src="item.pic" alt="" @load="onImageLoad($event)"/>
          </a>
        </wx-swiper-item>
      </wx-swiper>
    </div>
    <!-- 分开展示 -->
    <section class="members-imgad" v-else>
      <ul class="clearfix">
        <li v-for="(item,index) in tplItemData.dataset" :key="index" :style="{'margin-bottom':tplItemData.margin+'px'}">
          <a @click="openLink(item.link)" :title="item.showtitle">
            <img :src="item.pic" width="100%" />
          </a>
        </li>
      </ul>
    </section>
    
  </div>
</template>

<script>
import Vue from 'vue'
import { openPage } from '@/utils/utils'
import { Swipe, SwipeItem } from 'vant'
Vue.use(Swipe)
Vue.use(SwipeItem)
export default Vue.extend({
  props: {
    tplItemData: {
      type: Object // 传入参数的类型
    }
  },
  data() {
    return {
      imgadvWxH: '0',
      showIndicators: true,
      autoplay: true,
    }
  },
  methods: {
    // TODO 小程序跳转
    openLink(link) {
        openPage(link)
    },
    // TODO 小程序swiper获取图片高度
    onImageLoad(event){
      const imgHeight = event.detail.height
      if(imgHeight > parseFloat(this.imgadvWxH)){
        this.imgadvWxH = imgHeight+'px'
      }
    }
  },
})
</script>

<style lang="scss">
@import "src/styles/mixin";
.tpl16-swiper{
  .imgAdv-box{
    img{
      width: 100%;
    }
  }
  .members-imgad{
    li{
      margin-bottom: 10px;
      &:last-child{
        margin-bottom: 0;
        img{
          width: 100%;
        }
      }
    }
  }
}
</style>